package org.xiangsai.core;

import grpc.HelloGrpc;
import grpc.HelloMessage;
import io.grpc.Channel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;

/**
 * 客户端实现
 */
public class ClientDemo {

    public static void main(String[] args) {
        remoteCall("你好");
    }

    public static void remoteCall(String name)
    {
        HelloMessage.HelloRequest request= HelloMessage.HelloRequest.newBuilder().setName(name).build();
        HelloMessage.HelloResponse response = null;
        try{
            Channel channel= ManagedChannelBuilder.forAddress("localhost",50001).usePlaintext().build();
            HelloGrpc.HelloBlockingStub helloBlockingStub = HelloGrpc.newBlockingStub(channel);
            response=helloBlockingStub.sayHello(request);
        }
        catch (StatusRuntimeException ex)
        {
            System.out.println("error"+ex.toString());
        }
        System.out.println("client 调用远程sayHell()结果为："+response.getMessage());
    }
}
